package com.seaboxdata.interfaceJob;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;
import java.io.IOException;

/**
 * @author Woo_home
 * @create by 2020/5/3  13:54
 */
public class test {

    // 定义 MQ 连接地址
    private static final String ACTIVE_MQ_URL = "tcp://139.159.142.127:18090";

    // 定义主题名称
    private static final String TOPIC_NAME = "gpsRecord";

    public static void main(String[] args) throws JMSException, IOException {
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://139.159.142.127:18090");
        Connection connection = connectionFactory.createConnection();
        connection.start();
        Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic("gpsRecord");
        MessageConsumer consumer = session.createConsumer(topic);
        consumer.setMessageListener(new MessageListener() {
            @Override
            public void onMessage(Message message) {
                if(message instanceof TextMessage){
                    TextMessage textMessage = (TextMessage)message;
                    try {
                        System.out.println("the first consumer...");
                        System.out.println(textMessage.getText());
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
            }
        });
        System.in.read();
        consumer.close();
        session.close();
        connection.close();

    }
}
